package com.example.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.common.result.Result;
import com.example.entity.matirx.KeepContent;
import com.example.exception.BaseException;
import com.example.exception.SaveFailException;
import com.example.service.KeepContentService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/keepcontent")
@DS("mes")
@Api(tags = "保养项目相关",position = 998)
public class KeepContentController {
    @Autowired
    private KeepContentService contentService;

    @ApiOperation("新增保养项")
    @PostMapping("/save")
    public Result saveContent(@RequestBody KeepContent content) {
        boolean save = contentService.save(content);
        if (!save)throw new SaveFailException("保存保养项时出错");
        return Result.success();
    }
    @ApiOperation("删除保养项")
    @DeleteMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "保养项id可以多个", required = true, dataType = "int")
    })
    public Result deleteContent(@RequestBody List<Integer> ids){
        boolean b = contentService.removeByIds(ids);
        if (!b)throw new BaseException("删除保养项时出错");
        return Result.success();
    }
    @ApiOperation("修改保养项")
    @PostMapping("/edit")
    public Result editContent(@RequestBody KeepContent content){
        boolean b = contentService.updateById(content);
        if (!b)throw new BaseException("更新保养项时出错");
        return Result.success();
    }
}
